package masterjava.common.server.gwt.handlers;

import masterjava.common.server.gwt.ServerSerializeUtil;
import masterjava.common.server.gwt.rpc.RpcHandlerImpl;
import masterjava.common.settings.SettingValues;
import masterjava.common.shared.EntryMap;
import masterjava.common.shared.settings.SettingsRequest;
import masterjava.common.shared.settings.SettingsResponse;

import java.util.Map;

/**
 * User: gkislin
 * Date: 7/26/11
 */

public class SettingsHandler extends RpcHandlerImpl<SettingsRequest, SettingsResponse> {
    private final SettingValues settingValues;

    public SettingsHandler(SettingValues settingValues) {
        this.settingValues = settingValues;
    }

    @Override
    protected void handler(SettingsRequest request, SettingsResponse response) {
        EntryMap map = settingValues.getSettingValues();
        for (Map.Entry<String, Object> item : map.entrySet()) {
            map.put(item.getKey(), ServerSerializeUtil.toSerialize(item.getValue()));
        }
        response.setSettings(map);
    }
}
